<template>
  <!-- 添加或修改绑卡记录对话框 -->
  <el-dialog
    :title="title"
    :visible.sync="dialogVisible"
    width="1000px"
    append-to-body
    :close-on-click-modal="false"
    @close="close"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="98px" label-position="right"  class="flex-form" size="small">
      <el-form-item label="车辆编码" prop="veCustomsNo">
        <el-input v-model.trim="form.veCustomsNo" placeholder="请输入车辆编码" />
      </el-form-item>

      <el-form-item label="车牌号" prop="vehicleNo">
        <el-input v-model.trim="form.vehicleNo" placeholder="请输入车牌号" />
      </el-form-item>

      <el-form-item label="备案ID" prop="bindVehicleId">
        <el-input v-model.trim="form.bindVehicleId" placeholder="请输入备案ID" />
      </el-form-item>

      <el-form-item label="IC卡号" prop="cardNo">
        <el-input v-model.trim="form.cardNo" placeholder="请输入IC卡号" />
      </el-form-item>

      <el-form-item label="电子车牌" prop="rfid">
        <el-input v-model.trim="form.rfid" placeholder="请输入电子车牌" />
      </el-form-item>

      <el-form-item label="绑定时间" prop="bindTime">
        <el-date-picker clearable size="small"
                        v-model.trim="form.bindTime"
                        type="date"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择绑定时间">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="绑定状态">
        <el-radio-group v-model.trim="form.bindStatus">
          <el-radio
            v-for="dict in dict.type.sgs_vehicle_rd_code"
            :key="dict.value"
            :label="dict.value"
          >{{dict.label}}</el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="申报类型" prop="declType">
        <el-select v-model.trim="form.declType" placeholder="请选择申报类型">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>

      <el-form-item label="备注" prop="remark">
        <el-input v-model.trim="form.remark" placeholder="请输入备注" />
      </el-form-item>

    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="close">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { getPreVehicleBindcardRecord, addPreVehicleBindcardRecord, updatePreVehicleBindcardRecord } from "@/api/billsdecl/preVehicleBindcardRecord";
  export default {
    name: "PreVehicleBindcardRecord-addEdit",
    props: {
      dialogType: {
        type: String,
        default: "add",
      },
      rowData: {
        type: Object,
        default: () => {},
      },
      dict:{}
    },
    data() {
      return {
        // 弹出层
        dialogVisible: false,
        // 标题
        title: "新增",
        // 表单参数
        form: {
          id: null,
          veCustomsNo: null,
          vehicleNo: null,
          bindVehicleId: null,
          cardNo: null,
          rfid: null,
          bindTime: null,
          bindStatus: "0",
          declType: null,
          createBy: null,
          createTime: null,
          remark: null

        },
        // 绑卡记录表格数据
        preVehicleBindcardRecordList: [],
        // 表单校验
        rules: {
        }
      };
    },
    methods: {
      open() {
        this.dialogVisible = true;
        this.$nextTick(() => {
          if (this.dialogType == "add") {
            this.title = "新增";
          } else if (this.dialogType == "edit") {
            this.title = "编辑";
            this.loadDetail();
          } else if (this.dialogType == "detail") {
            this.title = "详情";
            this.loadDetail();
          }
        });
      },
      close() {
        this.$refs["form"].resetFields();
        this.dialogVisible = false;
      },

      // 获取详情
      loadDetail() {
        const id = this.rowData.id;
        getPreVehicleBindcardRecord(id).then((res) => {
          if (res.code == 200) {
            this.form = res.data;
          }
        });
      },

      // 提交表单
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            let params = {
              ...this.form,
            };
            if (this.dialogType == "add") {
              addPreVehicleBindcardRecord(this.form).then(res => {
                if (res.code === 200) {
                  this.$modal.msgSuccess("新增成功");
                  this.close();
                  this.$emit("handleQuery");
                }
              });
            } else {
              params.id = this.rowData.id;
              updatePreVehicleBindcardRecord(this.form).then(res => {
                if (res.code === 200) {
                  this.$modal.msgSuccess("修改成功");
                  this.close();
                  this.$emit("handleQuery");
                }
              });
            }
          }
        });
      },
    },
  };
</script>

<style lang="scss" scoped></style>
